#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "FileEnde.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    Init();
}

MainWindow::~MainWindow()
{
    delete ui;
}



void MainWindow::Init()
{
    this->centralWidget()->setLayout(ui->hMainLayout);
    ui->hMainLayout->setStretchFactor(ui->stackedWidget,8);
    ui->hMainLayout->setStretchFactor(ui->tabWidget,1);
    InitTabBtn();
    InitTabWidget();
    int iCom = btnVec.size()-wgVec.size();
    int num;
    if (iCom >= 0) {
        num = btnVec.size();
    }
    else {
        num = wgVec.size();
    }
    ui->tabWidget->setSpacing(0);
    ui->tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    ui->tabWidget->setViewMode(QListWidget::ListMode);
    ui->tabWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->tabWidget->setSizeAdjustPolicy(QListWidget::AdjustToContents);
    for (int i = 0; i < num; i++) {
        QListWidgetItem* temp = new QListWidgetItem(ui->tabWidget);
        QSize size = ui->tabWidget->size();
        size.setHeight(50);
        temp->setSizeHint(size);
        ui->tabWidget->setItemWidget(temp,btnVec[i]);
        btnVec[i]->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        btnVec[i]->setBaseSize(temp->sizeHint());

        int index = ui->stackedWidget->addWidget(wgVec[i]);
        btnVec[i]->tag = index;
        ui->stackedWidget->setCurrentIndex(btnVec[i]->tag);

    }
    //ui->stackedWidget->setCurrentIndex(0);
}

void MainWindow::InitTabBtn()
{
    KzToolBtn* firstBtn = new KzToolBtn(this);
    firstBtn->SetBtnText("主页");
  
    btnVec.push_back(firstBtn);
}
void MainWindow::InitTabWidget()
{
    FileEnde* endeWg = new FileEnde(this);
    wgVec.push_back(endeWg);
}

void MainWindow::InitConnect()
{}
